<%@ page language="java" contentType="text/html; charset=UTF-8"
	import="com.web.common.controller.AuthController"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	String appPath    = request.getContextPath();
	String version    = String.valueOf(System.currentTimeMillis());

	
	Object cookieObj = request.getSession().getAttribute(AuthController.COOKIE_EMAIL);
	String cookieEmail = "";
	if(cookieObj == null){
		cookieEmail = "";
	}
	else{
		cookieEmail = (String)cookieObj;	
	}
	
	Object msg = request.getSession().getAttribute(AuthController.AUTH_NOTICE);
	String msgSTr = "";
	if(msg == null){
		msgSTr = "";
	}
	else{
		msgSTr = (String)msg;	
	}
%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>用户登录</title>
	<jsp:include page="/plugins/bootstrap/include.jsp" />
	<link rel="stylesheet" type="text/css" href="<%=appPath%>/plugins/bootstrap/validator/css/bootstrapValidator.min.css">
	<link rel="stylesheet" type="text/css" href="<%=appPath%>/login/loginPage.css">
	<script type="text/javascript" src="<%=appPath%>/plugins/auth/jQuery.md5.js"></script>
	<script type="text/javascript" src="<%=appPath%>/plugins/bootstrap/validator/js/bootstrapValidator.min.js"></script>
</head>
<body >
	<div class="container">
	
	      <form id = "signForm" class="form-signin" role="form"  action="<%=appPath%>/auth/login">
	        <h2 class="form-signin-heading">用户登录</h2>
	        <div class="form-group">
	        	<label><%=msgSTr %></label>
	        </div>
	        <div class="form-group">
	        	<input id="email" name="email" type="email" class="form-control" placeholder="邮箱地址" required="" autofocus="" value=<%=cookieEmail %>>
	        </div>
	        <div class="form-group">
	        	<input id="pwd" name="pwd" type="password" class="form-control" placeholder="密码" required="">
	        </div>
	        <div class="form-group">
		        <div class="form-control">
		        	<input  id="cha" name="cha" type="text"   placeholder="验证码" required="">
		        	<img src="<%=appPath%>/jcaptcha.jpg"  title="看不清，点击换一个"  style="vertical-align: -5px;padding-left:4px" onclick="this.src='<%=appPath%>/jcaptcha.jpg?timestamp='+new Date().getTime()"/>
		        </div>
	        </div>
	        <div class="form-group">
	        	<input  id="timestamp" name="timestamp" type="hidden" value="<%=version%>">
	        </div>
	        <div class="form-group">
		        <div class="checkbox">
		          <label>
		            <input id="isremmber" name="isremmber" type="checkbox" value="yes"> 记住用户名
		          </label>
		        </div>
	        </div>
	        <div class="form-group">
	        	<button id="subBtn" type="submit" class="btn btn-lg btn-primary btn-block" >登录</button>
	        </div>
	      </form>

    </div> <!-- /container -->
    <script type='text/javascript'>
		(function(){
			var $signForm  = $('#signForm');
			var $email     = $('#email');
			var $pwd       = $('#pwd');
			var $timestamp = $('#timestamp');
			var $subBtn    = $('#subBtn');  
			
			$signForm.bootstrapValidator({
				message: '输入的值非法',
					feedbackIcons: {
								  valid: 'glyphicon glyphicon-ok',
								  invalid: 'glyphicon glyphicon-remove',
	 							  validating: 'glyphicon glyphicon-refresh'
		                         },
		            fields: {
		            	pwd: {
		                    message: '密码为空',
		                    validators: {
		                        notEmpty: {
		                            message: '密码为空'
		                        }
		                    }
		                },
		                cha: {
		                    message: '验证码为空',
		                    validators: {
		                        notEmpty: {
		                            message: '验证码为空'
		                        }
		                    }
		                },
		                email: {
		                    validators: {
		                        notEmpty: {
		                            message: '邮箱地址不能为空'
		                        },
		                        emailAddress: {
		                            message: '邮箱地址格式有误'
		                        }
		                    }
		                }
		            }
		        });
			$(document).keydown(function(event){ 
				if(event.keyCode==13){ 
					$subBtn.click(); 
				} 
			}); 
			
			$subBtn.click(function submit(){
				if($signForm.data('bootstrapValidator').isValid()){
					//alert($pwd.val()+$timestamp.val());
					var sign = $.md5($.md5($pwd.val())+$timestamp.val());
					$pwd.val(sign);
				}
			});
			
		})();
	</script>
}
</body>
</html>